import { appColor, themeColor } from "@/config/theme";
import { defineStore } from "pinia";

export const useSettingStore = defineStore({
  id: "setting",
  state: () => ({
    collapse: false,
    headerFixed: true,
    themeColor: themeColor,
    appColor: appColor,
    showNav: (localStorage.getItem("nil-app-is-show-nav") ?? "true") == "true",
  }),
  getters: {},
  actions: {
    setCollapse(flag) {
      if (typeof flag != "boolean") {
        throw TypeError("Collapse 的类型不符合预期(true | false)");
      }
      this.collapse = flag;
    },
    setHeaderFixed(flag) {
      if (typeof flag != "boolean") {
        throw TypeError("Collapse 的类型不符合预期(true | false)");
      }
      this.collapse = flag;
    },
    setShowNav(flag) {
      if (typeof flag != "boolean") {
        throw TypeError("Collapse 的类型不符合预期(true | false)");
      }
      localStorage.setItem("nil-app-is-show-nav", flag);
      this.showNav = flag;
    },
    setThemeColor(data) {
      this.themeColor = data;
    },
    setAppColor(data) {
      this.appColor = data;
    },
  },
});
